package lex.util;

/*
 * Due to rising concerns regaring the usage of Microsoft pictures in the
 * xp look and feel I decided to obfuscate the pictures and make them available
 * via the class SecretLoad which is not supplied as source code. If you
 * want to extend xp look and feel, please use
 * Image img = java.awt.Toolkit.getDefaultToolkit().createImage(url);
 * to load your images.s
 *
 */
import java.awt.Image;
import java.util.HashMap;
import javax.swing.ImageIcon;

public class ImageCache
{
	private static ImageCache instance = new ImageCache();
	private static final String LIQUID_PATH = "/icons/liquid/";
	private static final String MAC_PATH = "/icons/mac/";
	private static final String MAXTHON_PATH = "/icons/maxthon/";
	//================================
	private HashMap<String, Image> imageMap = null;

	private ImageCache()
	{
		imageMap = new HashMap<String, Image>();
	}

	public static ImageCache getInstance()
	{
		return instance;
	}
	
	public Image getImage( String path )
	{
		Image img = imageMap.get( path );
		if( img == null )
		{
			img = new ImageIcon( ImageCache.class.getResource( path ) )
					.getImage();
			imageMap.put( path, img );
		}
		return img;
	}

	public Image getLiquidImage( String fileName )
	{
		return this.getImage( LIQUID_PATH + fileName );
	}

	public Image getMacImage( String fileName )
	{
		return this.getImage( MAC_PATH + fileName );
	}

	public Image getMaxthonImage( String fileName )
	{
		return this.getImage( MAXTHON_PATH + fileName );
	}
}
